package com.financing.wap.web.controller.api;

import java.util.Collections;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.financing.wap.common.Pager;
import com.financing.wap.common.ResultMap;
import com.financing.wap.dto.DstVirtualGoodsDTO;
import com.financing.wap.service.IDstVirtualGoodsService;
import com.financing.wap.web.controller.BaseController;

@Controller("dstVirtualGoodsController")
@RequestMapping("/api/dstVirtualGoods")
public class DstVirtualGoodsController extends BaseController  { 

	private Logger logger = Logger.getLogger(getClass());
	
	@Autowired
	private IDstVirtualGoodsService dstVirtualGoodsService;
	
	@RequestMapping("/listDstVirtualGoods")
	@ResponseBody
	public ResultMap list(HttpServletRequest request, DstVirtualGoodsDTO dstVirtualGoods,Pager pager){
		ResultMap result = new ResultMap();
		
		try{
			logger.info("query dstVirtualGoods list begin .......");
			
			dstVirtualGoods.setBegin(pager.getStartIndex());
			dstVirtualGoods.setPageSize(pager.getPageSize());
			
			int count = dstVirtualGoodsService.queryListCount(dstVirtualGoods);
			
			pager.setTotalCount(count);
			
			List<DstVirtualGoodsDTO> dstVirtualGoodsList = null;
			
			if(count > 0){
				dstVirtualGoodsList = dstVirtualGoodsService.queryList(dstVirtualGoods);
			}else{
				dstVirtualGoodsList = Collections.emptyList();
			}
			result.setAttribute("pager", pager);
			result.setAttribute("list", dstVirtualGoodsList);
			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
			
			logger.info("query dstVirtualGoods list end .......");
		}catch(Exception e){
			log.error("query dstVirtualGoods error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		
		return result;
	}
	
	
}
